package cn.com.scitc.pano.controller;

import cn.com.scitc.pano.file.NameFilter;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.File;

@Controller
public class AdminWorkController {
    @RequestMapping(value = "work")
    public Object work(@RequestParam("id") Integer  id,@RequestParam("name") String name,Model model){
        String[] imagename = new String[30];
        File file = new File("D:/code/pano/src/main/resources/static/images/rotPhoto/" + name + "/" );
        NameFilter filter = new NameFilter("jpeg");
        File[] lf = file.listFiles(filter);
        int i =0;
        for ( ; i < lf.length; i++) {
            imagename[i] = lf[i].getName();
        }
        goodsname(model, name, imagename, file);
        return  "work";
    }
    static void goodsname(Model model, String name, String[] imagename, File file) {
        model.addAttribute("filename0", "/images/rotPhoto/" + name + "/" + imagename[0]);
        model.addAttribute("filename1", "/images/rotPhoto/" + name + "/" + imagename[1]);
        model.addAttribute("filename2", "/images/rotPhoto/" + name + "/" + imagename[2]);
        model.addAttribute("filename3", "/images/rotPhoto/" + name + "/" + imagename[3]);
        model.addAttribute("filename4", "/images/rotPhoto/" + name + "/" + imagename[4]);
        model.addAttribute("filename5", "/images/rotPhoto/" + name + "/" + imagename[5]);
        model.addAttribute("filename6", "/images/rotPhoto/" + name + "/" + imagename[6]);
        model.addAttribute("filename7", "/images/rotPhoto/" + name + "/" + imagename[7]);
        File fileone = new File("D:/code/pano/src/main/resources/static/images/rotPhoto/" + name);
        if (!fileone.exists()){
            model.addAttribute("goods","/prompt");
        }else {
            model.addAttribute("goods","/goods");
        }
        if (!file.exists()){
            model.addAttribute("works","/prompt");
        }else {
            model.addAttribute("works","/userwork");
        }
    }
}
